// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/store';
import axios from './assets/js/axios';
Vue.prototype.$axios = axios;
Vue.config.productionTip = false
import 'amfe-flexible';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
import './assets/css/base.css'
import vuescroll from 'vuescroll';
import './assets/iconfont/iconfont.css'
import qs from 'qs';
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp);
Vue.prototype.$qs = qs;
Vue.use(vuescroll, {
  ops: {
    scrollPanel: {
      scrollingX: false
    }
  }
})
Vue.directive('drag', {
  // 指令的定义
  bind: function (el) {
    let obj = el; // 获取当前元素
    obj.onmousedown = (e) => {
      // 算出鼠标相对元素的位置
      let disX = e.clientX - obj.offsetLeft;
      let disY = e.clientY - obj.offsetTop;

      document.onmousemove = (e) => {
        // 用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
        let left = e.clientX - disX;
        let top = e.clientY - disY;
        let docHeight = document.documentElement.clientHeight;
        let docWidth = document.documentElement.clientWidth;
        //console.log(obj.offsetHeight)
        if (top < 0 || left < 0 || docWidth - obj.offsetWidth < left || docHeight - obj.offsetHeight < top) {
          return;
        }
        obj.style.left = left + 'px';
        obj.style.top = top + 'px';
      };

      document.onmouseup = (e) => {
        document.onmousemove = null;
        document.onmouseup = null;
      }
    }
  }

})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
